[% setvar title Single quotes don't interpolate \' and \\ %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Single quotes don't interpolate \' and \\</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Nicholas Clark &lt;<a href='mailto:nick@talking.bollo.cx'>nick@talking.bollo.cx</a>&gt;
  Date: 28 Sep 2000
  Last Updated: 30 Sep 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 328
  Version: 3
  Status: Frozen</pre>
<a name='CHANGES'></a><h1>CHANGES</h1>
<p>Reissued on <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a> - I goofed the list.</p>
<p>Clarified the description slightly; by single quoted string I mean '' and q()</p>
<p>Updated discussion section</p>
<p>Frozen not withdrawn (see discussion section)</p>
<a name='DISCUSSION'></a><h1>DISCUSSION</h1>
<p>I'm in two minds as to whether to freeze or retract this RFC</p>
<p>Reaction was strongly polarised; three strongly against and one strongly
for. People valued their ability to use single quotes to easily make
strings containing single quotes. Michael Fowler expresses</p>
<pre>    Whew.  Disallowing escapes in a single-quote string does not make easy
    things easier and hard things possible.

    I'm not arguing that we should keep it simply because people are used
    to it, but instead we should keep it because it's useful.</pre>
<p>My view was that the majority are against the change, but views were from
<b>existing</b> perl users [who do you expect as the majority on perl6 lists?
:-)]. The change would penalise existing perl users, but benefit new perl
users (and presumably people teaching perl).</p>
<p>However, I'm wrong on that. Hildo Biersma states</p>
<pre>   Now, I have been teaching perl for a number of years, and nobody's ever
   had trouble with understanding how single quotes and the two escapes
   work.  Plenty of people find double-quotes either too powerful or too 
   limited (see the various RFCs), but I think single quotes are fine</pre>
<p>However, there was no comment on the secondary issue of how single
quotes treat unrecognised escapes. To me the following seems wrong:</p>
<pre>   $  perl -lwe &quot;print q(Quoted \( \\ \) Not \' \t \z)&quot;
   Quoted ( \ ) Not \' \t \z</pre>
<p>And from the archives:</p>
<pre>   Does it strike anyone else as odd that 'foo\\bar' eq 'foo\bar'?         
 </pre>
<p>(Steve Fink, <a href='http://www.mail-archive.com/perl6-language@perl.org/msg04008.html)' target='_blank'>www.mail-archive.com</a></p>
<p>I conclude</p>
<ul>
<li><a name='1 Removing \ escaping of \ and the delimiter from '' and q() would make perl less useful to the majority'></a>1 Removing <code>\</code> escaping of <code>\</code> and the delimiter from '' and q() would make perl less useful to the majority</li>
<li><a name='2 How '' and q() deal with \ followed by a non-escaped character isn't a major concern to perl programmers'></a>2 How '' and q() deal with <code>\</code> followed by a non-escaped character isn't a major concern to perl programmers</li>
</ul>
<p>hence escaping as is should remain, but it would be possible to change the
unrecognised escape behaviour (say <code>\z</code> maps to <code>z</code> like a &quot;&quot; string)
without causing pain, if this change were deemed sensible. My view is that
(2) should be considered, hence I freeze rather than withdraw the RFC.</p>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Remove all interpolation within single quotes and the <code>q()</code> operator, to
make single quotes 100% shell-like. <code>\</code> rather than <code>\\</code> gives a single
backslash; use double quotes or <code>q()</code> if you need a single quote in your
string.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Camel III (page 7) says &quot;Double quotation marks (double quotes) do
<i>variable interpolation</i> and <i>backslash interpolation</i> while single quotes
suppress interpolation.&quot;  Page 60 qualifies this with &quot;except for <code>\'</code> and
<code>\\</code>&quot;.</p>
<p>In perl single quotes are used to generate strings. Double quotes also generate
strings.</p>
<p>In C single quotes are used to make character constants. Double quotes are
used to make string constants. Backslash interpretation is performed in
single quotes in C. While multi-character constants are allowed by C, they
are strongly discouraged as they are non-portable, and a character constant
in C is a type distinct from a string constant. Hence double quotes and
single quotes signify different things.</p>
<p>In shell, single quotes are used to make strings. Double quotes also make
strings. Within single quotes backslashes are ordinary characters, and do
not quote anything. As one can't quote a <code>'</code> with a <code>\</code> there is no way to
interpolate a single quote within a single quoted string, but a workaround
such as <code>'don'\''t'</code> relying on the concatenation of <code>'don'</code> <code>\'</code> and
<code>'t'</code> achieves the desired results.</p>
<p>Hence perl's single quoted strings are analogous to shell's single quoted
strings, not C's. However, they're not identical, as perl allows <code>\\</code> to
mean an embedded <code>\</code>, <code>\'</code> to mean an embedded <code>'</code>.</p>
<p>This RFC argues that the exception is confusing and proposes to remove it.
This makes perl more regular in shell terms, and slightly more easy to learn
for the shell programmer.</p>
<p>It also makes perl internally simpler more regular. Currently the behaviour
for <code>q()</code> strings is that <code>\(</code> <code>\)</code> and <code>\\</code> map to 1 character,
<code>\</code><i>?</i> for all other <i>?</i> maps to 2 characters. <code>qq()</code> differs as
<code>\</code><i>?</i> maps to 1 character both when <i>?</i> is recognised as a backslash
escapes, <b>and</b> when it is unrecognised. A further irregularity is that
currently single quoted here docs don't interpolate <code>\\</code> or <code>\'</code>. The
consequence of this is that currently</p>
<pre>	'foo\\bar' eq 'foo\bar'</pre>
<p>which sure looks odd.</p>
<p>With this RFC it is proposed that in a single quoted string and the q()
operator <code>\</code> is not special. Hence <code>\</code><i>?</i> always maps to 2 characters
(<code>\</code> then <i>?</i>) unless <i>?</i> is the closing terminator, in which case the
string terminates with that <code>\</code> . Single quoted strings behave like single
quoted here docs, and like shell single quoted strings.</p>
<p>You don't lose any functionality, as</p>
<pre>   'don\'t implement this RFC, the benefits don\'t outweigh the confusion'</pre>
<p>can still be written</p>
<pre>   q(don't implement this RFC, the benefits don't outweigh the confusion)</pre>
<p>which is actually less typing.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Modify the tokeniser/lexer not to treat <code>\</code> as special, hence the first end
delimiter ends the string.</p>
<p>For 5.7's toke.c this doesn't appear that simple. it looks like
modifications would be needed to <code>S_tokeq</code>, <code>scan_str</code> and <code>Perl_yylex</code>
(for a quoted string at the start of curlies). There are probably more; the
code that makes single quoted strings interpolate <code>\'</code> and <code>\\</code> appear to
be deeply ingrained into the core.</p>
<p>The perl5 to perl6 converter would need to convert single quoted strings and
<code>q()</code> operators containing <code>\'</code> to the shortest (clearest?) equivalent of:</p>
<ul>
<li><a name='double quoted string with \Q...\E or \ escapes'></a>double quoted string with <code>\Q</code>...<code>\E</code> or  <code>\</code> escapes</li>
<li><a name='single quoted string(s) and explicit concatenation of &quot;'&quot;'></a>single quoted string(s) and explicit concatenation of <code>&quot;'&quot;</code></li>
<li><a name='q() operator with delimiters not in the string'></a><code>q()</code> operator with delimiters not in the string</li>
</ul>
<p>Single quoted strings containing <code>\\</code> but no quoting of delimiters would
need to have <code>\\</code> converted to <code>\</code></p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>Camel III - Programming Perl (3rd Edition)</p>
<p>perlop manpage for interpolation</p>
<p>RFC 226: Selective interpolation in single quotish context.</p>
<p>I believe that Larry Wall once made a comment about \' and \\ in single
quoted strings being a mistake, but I can't find any reference. The idea
certainly isn't mine, but I feel it worthy of consideration, even if
considered opinion is that any gain is to small to outweigh the upheaval.</p>
</div>
